package ${package.Controller};


import com.qooapp.base.dto.RR;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import ${package.Entity}.${entity};
import ${package.Entity}.query.${entity}Query;
import ${package.Service}.${table.serviceName};
<#if restControllerStyle>
import org.springframework.web.bind.annotation.RestController;
import lombok.extern.slf4j.Slf4j;
<#else>
import org.springframework.stereotype.Controller;
</#if>
<#if superControllerClassPackage??>
import ${superControllerClassPackage};
</#if>

/**
 * <p>
 * ${table.comment!} 前端控制器
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
<#if restControllerStyle>
@RestController
@Slf4j
<#else>
@Controller
</#if>
@RequestMapping("<#if package.ModuleName?? && package.ModuleName != "">/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>${table.entityPath}</#if>")
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
<#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
<#else>
public class ${table.controllerName} {
</#if>

   public final  ${table.serviceName} ${table.entityPath}Service;

    public ${table.controllerName}(${table.serviceName} ${table.entityPath}Service) {
    this.${table.entityPath}Service = ${table.entityPath}Service;
    }

    /**
    * 查詢列表
    * @param query
    * @return
    */
    @RequestMapping(value="/",method=RequestMethod.GET)
    public RR queryPage(@RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
                        @RequestParam(value = "pageNum",defaultValue = "10") Integer pageSize,
                        ${entity}Query query){
        //自己實現。。。。。。。。
        IPage<${entity}> page = new Page<>(pageNum,pageSize);
        Page<${entity}> sysUserPage = ${table.entityPath}Service.queryPage(page, query);
        return RR.ok(sysUserPage);
    }




    /**
    * 修改
    * @param ${table.entityPath}
    * @return
    */
    @RequestMapping(value="/",method=RequestMethod.POST)
    public RR update( ${entity} ${table.entityPath}){
       //自己實現。。。。。。。。
        return null;
    }


    /**
    * 删除对象信息
    * @param id
    * @return
    */
    @RequestMapping(value="/{id}",method=RequestMethod.DELETE)
    public RR delete(@PathVariable("id")  Long id){
        try {
    ${table.entityPath}Service.removeById(id);
        return RR.ok();
        } catch (Exception e) {
            log.error("刪除失敗： -> {}",e.getMessage());
        return RR.error("刪除失敗！");
        }
    }


   /**
   * 詳情
   * @param id
   * @return
   */
   @RequestMapping(value="/{id}",method=RequestMethod.GET)
   public RR get(@PathVariable("id") Long id){
    ${entity} ${table.entityPath} =  ${table.entityPath}Service.getById(id);
      return RR.ok(${table.entityPath});
   }

 }
</#if>
